import axios from 'axios'
import qs from 'qs'

// 创建一个包含默认配置的axios实例
const axiosInstance = axios.create({
  withCredentials: true, // 确保跨域请求时携带cookie
  headers: {
    'Content-Type': 'application/json',
    'X-Requested-With': 'XMLHttpRequest'
  }
})

/** 获取房间列表 */
export const getRoomList = (params: object) => {
    return axiosInstance.get('/api/room/listAll.do', { params })
}
/** 创建房间 */
export const createRoom = (params: object) => {
    return axiosInstance.post('/api/room/add.do', qs.stringify(params), {
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    })
}
/** 更新房间 */
export const updateRoom = (params: object) => {
    return axiosInstance.post('/api/room/update.do', qs.stringify(params), {
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    })
}
/** 删除房间 */
export const deleteRoom = (roomType: string, hotelName: string) => {
    return axiosInstance.post('/api/room/delete.do', qs.stringify({ roomType, hotelName }), {
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    })
}
